package com.cskaoyan.market.service.wx;

import com.cskaoyan.market.db.domain.MarketOrder;
import com.cskaoyan.market.db.domain.MarketOrderExample;
import com.cskaoyan.market.db.mapper.MarketCommentMapper;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: chenjian
 * @Date: 2024/5/19 16:32
 */
@Service
public class WxIndexServiceImpl implements WxIndexService {
    @Autowired
    MarketCommentMapper marketCommentMapper;
    @Autowired
    MarketOrderMapper marketOrderMapper;
    @Override
    public OrderVo showIndex(Integer userId) {
        Integer uncomment = 0;
        Integer unpaid=0;
        Integer unrecv=0;
        Integer unship=0;

        MarketOrderExample marketOrderExample = new MarketOrderExample();
        MarketOrderExample.Criteria criteria = marketOrderExample.createCriteria();
        criteria.andUserIdEqualTo(userId).andLogicalDeleted(true);
        List<MarketOrder> marketOrders = marketOrderMapper.selectByExample(marketOrderExample);


        for (MarketOrder marketOrder : marketOrders) {
            if(marketOrder.getOrderStatus()==101){
                unpaid++;
            }else if(marketOrder.getOrderStatus()==301){
                unrecv++;
            }else if(marketOrder.getOrderStatus()==201){
                unship++;
            } else if (marketOrder.getOrderStatus()==401) {
                uncomment++;
            }
        }
        return new OrderVo(uncomment,unpaid,unrecv,unship);
    }
}
